import React from 'react';
import {Tabs} from 'antd';
import { connect } from 'react-redux';
import OrgStructure from './org-structure';
import DepartmentGroupComp from "containers/setting/department-group/department-group";
const TabPane = Tabs.TabPane;
class OrgStructureIndex extends React.Component{
  constructor(props) {
    super(props);
    this.state={}
  }
  render() {
    const {currentPageRoute, authPolicyAll}= this.props;
    const {subFunctions}= currentPageRoute;
    return (
      <div className='org-structure-wrapper full-height-page full-page-margin'>
        <Tabs tabPosition='top'>
          {
            subFunctions.map(item=>{
              const key = item.key;
              return (
                item.operationType !== 'H' &&
                  <TabPane tab={item.resourceName} key={key}>
                    {
                      key === 'department-tab' &&
                      <OrgStructure authPolicyAll={authPolicyAll}
                                    isReadonly={item.operationType === 'R'}/>
                    }
                    {
                      key === 'department-group' &&
                      <DepartmentGroupComp  authPolicyAll={authPolicyAll}
                                            isReadonly={!authPolicyAll || item.operationType === 'R'}/>
                    }
                  </TabPane>
              )})
          }
        </Tabs>
      </div>
    )
  }
}

function mapStateToProps(state) {
  return {
    currentPageRoute: state.main.currentPageRoute,
    authPolicyAll: state.main.authPolicyAll
  }
}

export default connect(mapStateToProps)(OrgStructureIndex);
